package com.suptrack.web.servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.suptrack.entity.Car;
import com.suptrack.entity.User;
import com.suptrack.service.CarService;
import com.suptrack.service.UserService;

/**
 * Servlet implementation class addCarServlet
 */
@WebServlet("/RegisteredContent/addCar")
public class addCarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
@EJB
CarService carservice;
@EJB
UserService userservice;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User _owner = (User) request.getSession().getAttribute("User");
		String _name = request.getParameter("C_name");
		String _brand = request.getParameter("C_brand");
		String _year = request.getParameter("C_year");
		Car _car = new Car();
		_car.setBrand(_brand);
		_car.setName(_name);
		_car.setFirstEntryYear(_year);
		_car.setUser(_owner);
		
		
		carservice.addCarService(_car);
		
		response.sendRedirect(request.getServletContext().getContextPath()+"/RegisteredContent/ManageCar");
		
		
	}

}
